using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Catastrophe.Common.FileM;

namespace BaseAmd.Mmp.FileNameFormat
{
	public class FileRenameSsh : BaseFileRename
	{
		public override FileInfoEntity FileNameFormat(string fullName, List<string> extName)
		{
			if (!File.Exists(fullName))
			{
				return null;
			}
			FileInfoEntity fileInfoEntity = FileUtil.GetFileInfoEntity(fullName, extName);
			FileInfo fileInfo = new FileInfo(fullName);
			Tuple<bool, string, string, string> tuple = this.NameFormat(fileInfo.Name);
			fileInfoEntity.FormatName = tuple.Item2;
			return fileInfoEntity;
		}

		public override Tuple<bool, string, string> NameFormatReverse(string name)
		{
			string[] array = name.Split('_');
			if (array.Length >= 4 && array[0] == "" && array[1] == "N" && array.Last().Trim() != "")
			{
				string text = "";
				string text2 = array.Last();
				for (int i = 2; i < array.Length - 1; i++)
				{
					text += array[i];
				}
				return new Tuple<bool, string, string>(item1: true, text.ToLower() + "." + text2.ToLower(), "." + text2.ToLower());
			}
			return new Tuple<bool, string, string>(item1: false, "", "");
		}

		public override Tuple<bool, string, string, string> NameFormat(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				throw new ArgumentNullException();
			}
			if (name.Contains('.'))
			{
				string[] source = name.Split('.');
				string text = source.Last();
				string text2 = name.Replace("." + text, "");
				if (text2.Contains('_'))
				{
					text2 = text2.Replace("_", "");
				}
				return new Tuple<bool, string, string, string>(item1: true, "_N_" + text2.ToUpper() + "_" + text.ToUpper(), text2, text.ToUpper());
			}
			return new Tuple<bool, string, string, string>(item1: false, "", "", "");
		}

		public override Tuple<string, string> RenameIdIncrease(ref string nameWithOutE, string extend, ref int id)
		{
			string text = "";
			string text2 = "";
			char c = '-';
			if (nameWithOutE.Contains(c))
			{
				string[] source = nameWithOutE.Split(c);
				string text3 = source.Last();
				string text4 = nameWithOutE.Replace(c + text3, "");
				int.TryParse(text3, out id);
				id++;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(0, 2);
				defaultInterpolatedStringHandler.AppendFormatted(c);
				defaultInterpolatedStringHandler.AppendFormatted(id);
				nameWithOutE = text4 + defaultInterpolatedStringHandler.ToStringAndClear();
				text = nameWithOutE + "." + extend.ToLower();
				text2 = "_N_" + text4.ToUpper() + c + id + "_" + extend.ToUpper();
			}
			else
			{
				id++;
				text = nameWithOutE + c + id + "." + extend.ToLower();
				text2 = "_N_" + nameWithOutE.ToUpper() + c + id + "_" + extend.ToUpper();
				string obj = nameWithOutE;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(0, 2);
				defaultInterpolatedStringHandler.AppendFormatted(c);
				defaultInterpolatedStringHandler.AppendFormatted(id);
				nameWithOutE = obj + defaultInterpolatedStringHandler.ToStringAndClear();
			}
			return new Tuple<string, string>(text, text2);
		}
	}
}
